//
//  promotionInfoView.m
//  代码布局
//
//  Created by iOS on 16/8/5.
//  Copyright © 2016年 iOS. All rights reserved.
//

#import "promotionInfoView.h"
#import "DWTagList.h"
@implementation promotionInfoView

- (instancetype)init{
    if (self = [super init]) {
        self.backgroundColor = [UIColor yellowColor];
    }
    return self;
}
- (void)setPromotionDict:(NSDictionary *)promotionDict{
    _promotionDict = promotionDict;
  NSArray* keyArray =  [promotionDict allKeys];
    NSInteger k = 0;
    if (keyArray.count > 2) {
        k = 2;
    }else{
        k = keyArray.count;
    }
    CGFloat labelCount = 0;
    for (NSInteger i = 0; i<k; i++) {
        
        labelCount = i;
    CGSize size1 = [getStringOfHeightOfReact getstring:keyArray[i] AndFont:fontNunber(12)];
     CGSize size2 = [getStringOfHeightOfReact getstring:promotionDict[keyArray[i]] AndFont:fontNunber(14)];
    UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(0,(size2.height - size1.height)/2.0 + size2.height *i, size1.width,size1.height )];
    
    label1.text = keyArray[i];
    label1.font = [UIFont systemFontOfSize:fontNunber(11)];
        label1.textColor = [UIColor redColor];
    [label1.layer setBorderWidth:1.0];
    label1.layer.borderColor = [UIColor redColor].CGColor;
    [label1.layer setMasksToBounds:YES];
    [label1.layer setCornerRadius:size1.height/4.0];
    label1.textAlignment = 1;
    [self addSubview:label1];
   
    UILabel * labelinfo = [[UILabel alloc]initWithFrame:CGRectMake(size1.width + 10, size2.height*i, self.frame.size.width - size1.width - 10, size2.height)];
    labelinfo.text = promotionDict[keyArray[i]];
    labelinfo.font = [UIFont systemFontOfSize:fontNunber(13)];
    [self addSubview:labelinfo];
    NSLog(@"款 = %f",self.frame.size.width);
        label1.tag = 111+i;
    }
    UILabel * label = (UILabel*)[self viewWithTag:111 + labelCount];
   DWTagList * tagList = [[DWTagList alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(label.frame)+3, self.frame.size.width, 100.0f)];
    NSArray *array = [[NSArray alloc]init];
    [tagList setTags:keyArray];
    [self addSubview:tagList];
    tagList.labelBackgroundColor = [UIColor whiteColor];
     NSLog(@"tagheight ==%f %f",[tagList fittedSize].height ,CGRectGetMaxY(label.frame));
    sizeFit = CGSizeMake(self.frame.size.width, CGRectGetMaxY(label.frame) + 3 + [tagList fittedSize].height);
    CGRect frame = tagList.frame;
    frame.size = [tagList fittedSize];
    tagList.frame = frame;
}
- (CGSize)fittedSize{
    return sizeFit;
}
@end
